<?php

namespace App\Http\Requests;

use Illuminate\Support\Facades\Request;

/**
 * 用户Request验证类
 * Class UserRequest
 * @package App\Http\Requests
 */
class UserUpdateRequest extends BaseRequest
{
    /**
     * 这个地方记得为 true, 默认为 false 会返回 403 未授权提示
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * 验证规则
     * @return array
     */
    public function rules()
    {
        $id = $this->route('id');
        return [
            'nickname' => 'sometimes|required|min:2|max:32|unique:users,nickname,'.$id ,
            'phone'    => ['sometimes', 'required' , 'integer' , 'regex:/^1(3|4|5|6|7|8|9)[\d]{9}$/' , 'unique:users,phone,'.$id] ,
            'status'   => 'sometimes|required',
        ];
    }

    /**
     * 验证不通过提示
     * @return string[]
     */
    public function messages()
    {
        return [
            'nickname.required' => '用户名不能为空',
            'nickname.unique'   => '用户名已存在',
            'phone.required'    => '请输入手机号',
            'phone.unique'      => '手机号已存在',
            'phone.integer'     => '手机号格式不正确',
            'phone.regex'       => '手机号格式错误',
            'status.required'   => '状态必填',
        ];
    }

}
